package com.nl.sq;

import java.util.Stack;
public class StackQueue<T> {

	//stack1 增加，stack2弹出
	Stack<T> stack1, stack2;
	int length;

	public StackQueue() {
		stack1 = new Stack<T>();
		stack2 = new Stack<T>();
		length=0;
	}

	public void appendToTail(T t) {
		stack1.push(t);
		length++;
	}

	public T deleteHead() {
		if (stack2.isEmpty()) {
			while (!stack1.isEmpty()) {
				stack2.push(stack1.pop());
			}
		}

		if (!stack2.isEmpty()) {
			length--;
			return stack2.pop();
		} else {
			return null;
		}

	}
	public boolean isEmpty(){
		return length==0;
	}
	public static void main(String[] args) {
		StackQueue<Integer> queue = new StackQueue<Integer>();
		for(int i=0;i<10;i++){
			queue.appendToTail(i);
		}
		while(!queue.isEmpty()){
			System.out.println(queue.deleteHead());
		}
	}

}
